gh-142781: Fix type confusion in zoneinfo weak cache#142925
gh-142781: Fix type confusion in zoneinfo weak cache#142925superboy-zjc wants to merge 7 commits intopython:mainfrom
Conversation
Validate the types returned from _weak_cache.get() and _weak_cache.setdefault() to prevent type confusion when a ZoneInfo subclass provides a misbehaving cache implementation.
Misc/NEWS.d/next/Library/2025-12-18-00-14-16.gh-issue-142781.gcOeYF.rst
Outdated
Show resolved
Hide resolved
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
…sage, rewriting NEWS and improving unit test
|
Thanks for the review! I have addressed all the comments above. Ready for another look. |
picnixz
left a comment
There was a problem hiding this comment.
You should update the branch as we ZoneInfo was modified recently.
Thanks for your advice! All comments are resolved. Let me know if anything else is needed! |
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
| if (!PyObject_TypeCheck(instance, type)) { | ||
| PyErr_Format(PyExc_RuntimeError, | ||
| "Unexpected instance of %T in %s weak cache for key %R", | ||
| instance, type->tp_name, key); |
There was a problem hiding this comment.
You can use _PyType_Name() instead of tp_name. It always returns a short name.
Validate the types returned from
_weak_cache.get()and_weak_cache.setdefault()to prevent type confusion when a ZoneInfo subclass provides a misbehaving cache implementation.Fixes gh-142781.